﻿using ERPSystem.Common.Domains.CustomerProfileCommon;
using ERPSystem.Common.DTO;
using ERPSystem.Common.Infrastructure.IRepository;
using MediatR;

namespace BasicInformationCommon.API.BasicInformationCommons.DropDownCommon.CreditRatingRead
{
    public class CreditRatingQueryHandler : IRequestHandler<CreditRatingQueryCommand, Result>
    {
        private readonly IBaseRepository<CreditRating> _creditRatingRepository;

        public CreditRatingQueryHandler(IBaseRepository<CreditRating> creditRatingRepository)
        {
            _creditRatingRepository = creditRatingRepository;
        }
        /// <summary>
        /// 查询信用等级业务逻辑
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Result> Handle(CreditRatingQueryCommand request, CancellationToken cancellationToken)
        {
            var result = new Result();
            try
            {
                var creditRatingQuery = await(await _creditRatingRepository.GetAll()).ToListAsync();
                result.Data = creditRatingQuery;
            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
